﻿@model IEnumerable<InitialNavigation>
@{
    Layout = "_ControlPanel";
    NavigationService navigationService = new NavigationService();
    var userId = UserContext.CurrentUser.UserId;  
}
@section Aside
{
    @Html.Action("_CommonOperationMenu", "ControlPanel")
}
@using (Html.BeginForm("AddCommonOperations", "ControlPanel", FormMethod.Post))
{ 
    <div class="tn-block">
        <div class="tnc-main">
            <div class="tnc-ctn-center">
                <h1>
                    <span>添加常用操作</span></h1>
                <div class="tnc-ctnright-list">
                    @Html.StatusMessage()
                    <div class="tn-directory">
                        @foreach (InitialNavigation navigation in Model)
                        {
                            if (navigation.NavigationText != "主页" && navigation.IsEnabled)
                            {
                            <h5 class="tn-directory-path">
                                @if (!string.IsNullOrEmpty(navigation.NavigationText))
                                { 
                                    @navigation.NavigationText
                                }
                                else
                                {
                                    @Tunynet.Globalization.ResourceAccessor.GetString(navigation.ResourceName)
                                }
                            </h5>
                            <div class="tn-directory-level tn-border-gray tn-border-bottom">
                                @if (navigation.Children.Count() > 0)
                                {
                                    foreach (InitialNavigation children in navigation.Children)
                                    {
                                        if (children.Children.Count() > 0)
                                        {
                                            foreach (InitialNavigation child in children.Children)
                                            {
                                                if (child.IsEnabled)
                                                {
                                    @Html.SipmleCheckBox("navigationIds", child.NavigationId, navigationService.GetCommonOperation(child.NavigationId, userId) != null, new { @class = "IsCommonOperation", id = "navigationIds-" + child.NavigationId })
                                    <label class="tn-directory-item" for="navigationIds-@child.NavigationId">
                                        @if (!string.IsNullOrEmpty(child.NavigationText))
                                        { 
                                            @child.NavigationText
                                        }
                                        else
                                        {
                                            @Tunynet.Globalization.ResourceAccessor.GetString(child.ResourceName)
                                        }</label>
                                                }
                                            }
                                        }
                                    }
                                }
                            </div>
                            }
                        }
                        @Html.Button("提交", ButtonTypes.Submit, HighlightStyles.Primary)
                    </div>
                </div>
            </div>
        </div>
    </div>
}
<script type="text/javascript" language="javascript">
    $(function () {
        $(".IsCommonOperation").click(function (e) {

            if ($("form input[name='navigationIds']:checked").length > 10) {
                e.preventDefault();
                alert("最多选择10个常用操作");
                return;
            }
        });
    });
</script>
